using TMS.Api.Session;
using TMS.Application.Common.Interface;
using TMS.Infrastructrue;
using TMS.Infrastructrue.Filters;

var builder = WebApplication.CreateBuilder(args);
//跨域的问题
builder.Services.AddCors(options =>
        {
            options.AddDefaultPolicy(
                policy =>
                {
                    policy.AllowAnyHeader().AllowAnyMethod().AllowAnyOrigin();
                });
        });

builder.Services.AddControllers(options =>
{
    // options.Filters.Add(typeof(AuditLogActionFilter));
    // options.Filters.Add(typeof(HttpGlobalExceptionFilter));
});
//注册http请求上下文
builder.Services.AddHttpContextAccessor();

//注册当前信息服务
builder.Services.AddTransient(typeof(ISessionService), typeof(SessionUserService));
// Add services to the container.

builder.Services.AddControllers();
// Learn more about configuring Swagger/OpenAPI at https://aka.ms/aspnetcore/swashbuckle
builder.Services.AddEndpointsApiExplorer();
builder.Services.AddSwaggerGen();

builder.Services.AddInfrastructure(builder.Configuration);

var app = builder.Build();

// Configure the HTTP request pipeline.
if (app.Environment.IsDevelopment())
{
    app.UseSwagger();
    app.UseSwaggerUI();
}

app.UseCors();

app.UseAuthorization();

app.MapControllers();

app.MigrateDatabase();

app.Run();
